//
//  XJTiXianSectionHeaderView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/24.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJTiXianSectionHeaderView.h"
@interface XJTiXianSectionHeaderView()
@property(nonatomic, strong) UIView *bgView;
@property(nonatomic, strong) UILabel *titleLb;
@property(nonatomic, strong) UIButton *accountManageButton; //账户管理 按钮
@end

@implementation XJTiXianSectionHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.titleLb];
    [self.bgView addSubview:self.accountManageButton];
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)titleLb {
    if (!_titleLb) {
        _titleLb = [[UILabel alloc] init];
        _titleLb.font = XJFONTSET_M(18.0);
    }
    return _titleLb;
}

- (UIButton *)accountManageButton {
    if (!_accountManageButton) {
        _accountManageButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_accountManageButton setTitle:@"账户管理>" forState:(UIControlStateNormal)];
        [_accountManageButton setTitleColor:XJCOLOR_RGB(110, 110, 110) forState:(UIControlStateNormal)];
        _accountManageButton.titleLabel.font = XJFONTSET_R(13.0);
        
        _accountManageButton.hidden = YES; //默认影藏
        [_accountManageButton addTarget:self action:@selector(accountManageButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _accountManageButton;
}


#pragma mark - layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(15);
        make.top.bottom.equalTo(self.bgView);
        make.right.equalTo(self.accountManageButton.mas_left).offset(-10);
    }];
    [self.accountManageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.bgView);
        make.right.equalTo(self.bgView.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(80, 20));
    }];
}
#pragma mark - 配置 & 事件回调
- (void)accountManageButtonAction {
    XJLog(@"小鸡小鸡进行解析");
    
    if (self.clickTiXianManagerBlock) {
        self.clickTiXianManagerBlock();
    }
}


- (void)configureXJTixianSecitonHeaderWithTitle:(NSString *)title section:(NSInteger)section {
    self.titleLb.text = title;
    
    
    if (section == 0) { //区头一不显示

        self.accountManageButton.hidden = YES;
    }else { 
        self.accountManageButton.hidden = NO;
    }
}




@end
